package utility;


import java.io.IOException;

public class Filepermission 
{	
	public static void setReadOnly(String path)
	{
		String osName = System.getProperty("os.name");
		System.out.println(osName);
		String command;
		 try 
		 { 
			 if (osName.equalsIgnoreCase("WINDOWS NT") ||	osName.equals("Windows 2000") )
				 command = "attrib +r "+path;
					//command = "cmd.exe /c attrib +r "+path;
				else if(osName.equals("Linux"))
				    	 command ="chmod 400 "+path;
				else
					command = " attrib +r "+path;
			 System.out.print(command);
			 Runtime.getRuntime().exec(command);
		} 
		 catch (IOException e) 
		 {
			e.printStackTrace();
		}
	}
	
	public static void setReadWrite(String path)
	{
		String osName = System.getProperty("os.name");
		String command;
		System.out.println(osName);
		 try 
		 {
			if (osName.equalsIgnoreCase("WINDOWS NT") ||	osName.equals("Windows 2000") )
				command = "attrib -r "+path;
				//command = "cmd.exe /c attrib -r "+path;
			else if(osName.equals("Linux"))
			    	 command ="chmod 600 "+path;
			else
				command = " 	attrib -r "+path;
				//command = "command.com  	attrib -r "+path;
			System.out.print(command);
			Runtime.getRuntime().exec(command);
		} 
		 catch (IOException e) 
		 {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) 
	{
		Filepermission.setReadOnly("C:\\temp.txt");
	}
}

